home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / TransSkel / Demos / Pascal Demos / Button / Dialog3.p < prev    next >
Text File  |  1994-02-23  |  4KB  |  155 lines

  1.  { Bugs }
  2.  
  3.  
  4. unit Dialog3;
  5.  
  6. interface
  7.  
  8.     uses
  9.         TransSkel, ButtonGlobals;
  10.  
  11.  
  12.     procedure DoDialog3;
  13.  
  14. implementation
  15.  
  16.     const
  17.  
  18.         iPushDismiss = 1;
  19.         iPushButton1 = 2;
  20.         iPushButton2 = 3;
  21.         iPushButton3 = 4;
  22.         iRadioStaticText = 5;
  23.         iRadioButton1 = 6;
  24.         iRadioButton2 = 7;
  25.         iRadioButton3 = 8;
  26.         iRadioNone = 9;
  27.         iCheckStaticText = 10;
  28.         iCheckButton1 = 11;
  29.         iCheckButton2 = 12;
  30.         iCheckButton3 = 13;
  31.         iOutline = 14;
  32.  
  33.  
  34.     var
  35.  
  36.         defaultButton: Integer;
  37.  
  38.  
  39. {--------------------------------------------------------------------}
  40. { Dialog 3 procedures }
  41. {--------------------------------------------------------------------}
  42.  
  43.     procedure OutlineButton (dlog: DialogPtr;
  44.                                     item: Integer);
  45.     begin
  46.         SkelDrawButtonOutline(SkelGetDlogCtl(dlog, defaultButton));
  47.     end;
  48.  
  49.  
  50.     procedure InstallOutliner (dlog: DialogPtr;
  51.                                     item: Integer);
  52.         var
  53.             r: Rect;
  54.     begin
  55.         SkelGetDlogRect(dlog, item, r);
  56.         InsetRect(r, -4, -4);
  57.         SkelSetDlogRect(dlog, iOutline, r);
  58.         SkelSetDlogProc(dlog, iOutline, @OutlineButton);
  59.         SkelDrawButtonOutline(SkelGetDlogCtl(dlog, defaultButton));
  60.     end;
  61.  
  62.  
  63.     procedure RemoveOutliner (dlog: DialogPtr);
  64.     begin
  65.         SkelSetDlogProc(dlog, iOutline, nil);
  66.         SkelEraseButtonOutline(SkelGetDlogCtl(dlog, defaultButton));
  67.     end;
  68.  
  69.  
  70.     procedure SetDefaultButton (dlog: DialogPtr;
  71.                                     item: Integer);
  72.     begin
  73.         if (defaultButton <> 0) then
  74.             RemoveOutliner(dlog);
  75.         defaultButton := item;
  76.         if (defaultButton <> 0) then
  77.             InstallOutliner(dlog, defaultButton);
  78.     end;
  79.  
  80.  
  81.     procedure DoDialog3;
  82.         var
  83.             filter: ModalFilterProcPtr;
  84.             dlog: DialogPtr;
  85.             savePort: GrafPtr;
  86.             item: Integer;
  87.             value: Integer;
  88.             hilite: Integer;
  89.             loop: Boolean;
  90.     begin
  91.         dlog := GetNewDialog(dlog3Res, nil, WindowPtr(-1));
  92.         if (dlog = DialogPtr(nil)) then
  93.             begin
  94.                 SysBeep(1);
  95.                 exit(DoDialog3);
  96.             end;
  97.  
  98.         SkelPositionWindow(dlog, skelPositionOnMainDevice, horizRatio, vertRatio);
  99.  
  100.         GetPort(savePort);
  101.         SetPort(dlog);
  102.  
  103.         SetDefaultButton(dlog, iPushButton1);
  104.         SkelSetDlogCtlValue(dlog, iCheckButton1, 1);
  105.         SkelSetDlogCtlValue(dlog, iCheckButton2, 1);
  106.         SkelSetDlogCtlValue(dlog, iCheckButton3, 1);
  107.         SkelSetDlogRadioButtonSet(dlog, iRadioButton1, iRadioNone, iRadioButton1);
  108.  
  109.         ShowWindow(dlog);
  110.  
  111.         loop := true;
  112.         while (loop) do
  113.             begin
  114.                 filter := SkelDlogFilter(nil, false);
  115.                 SkelDlogDefaultItem(defaultButton); { turns off if zero }
  116.                 ModalDialog(filter, item);
  117.                 SkelRmveDlogFilter;
  118.                 case item of
  119.                     iPushDismiss: 
  120.                         loop := false;
  121.                     iPushButton1, iPushButton2, iPushButton3: 
  122.                         begin
  123.                             { ignore hits in these items }
  124.                         end;
  125.                     iRadioButton1, iRadioButton2, iRadioButton3: 
  126.                         begin
  127.                             SkelSetDlogRadioButtonSet(dlog, iRadioButton1, iRadioNone, item);
  128.                             { remap item number from radio button range into pushbutton range }
  129.                             item := item + iPushButton1 - iRadioButton1;
  130.                             SetDefaultButton(dlog, item);
  131.                         end;
  132.                     iRadioNone: 
  133.                         begin
  134.                             SkelSetDlogRadioButtonSet(dlog, iRadioButton1, iRadioNone, item);
  135.                             SetDefaultButton(dlog, 0);    { no default button }
  136.                         end;
  137.                     iCheckButton1, iCheckButton2, iCheckButton3: 
  138.                         begin
  139.                             value := SkelToggleDlogCtlValue(dlog, item);
  140.                             if (value <> 0) then
  141.                                 hilite := normalHilite
  142.                             else
  143.                                 hilite := dimHilite;
  144.                             { remap item number from checkbox range into pushbutton range }
  145.                             item := item + iPushButton1 - iCheckButton1;
  146.                             if (SkelSetDlogCtlHilite(dlog, item, hilite) and (item = defaultButton)) then
  147.                                 SkelDrawButtonOutline(SkelGetDlogCtl(dlog, item));
  148.                         end;
  149.                 end;
  150.             end;
  151.         DisposeDialog(dlog);
  152.         SetPort(savePort);
  153.     end;
  154.  
  155. end.